import os
import pickle
class A:
    saved = []

    def __init__(self, name =None):
        self.name = name
        self.filename = self.name + '.pk2'

    def __get__(self, insance, owner):
        if self.name not in A.saved:
            raise ArithmeticError("%s 属性还没赋值！" % self.name)
        with open(self.filename, 'rb') as f:
            value = pickle.load(f)
        return value

    def __set__(self, insance, value):
        with open(self.filename, 'wb') as f:
            pickle.dump(value, f)
            A.saved.append(self.name)

    def __delete__(self, insance):
        os.remove(self.filename)
        A.saved.remove(self.name)

class Test:
    x = A('x')
    y = A('y')
    z = A('z')

test = Test()
test.x = 123
test.y = 'i ci islid'
test.z = 12.13
print(test.x)
print(test.y)
print(test.z)
